<template>
        <div>
        <div class="title">
            <van-nav-bar
                title="编辑地址"
                left-text="返回"
                left-arrow
                @click-left="onClickLeft"
            />           
        </div>
        <div class="address">
            <van-address-edit
                :area-list="areaList"
                show-set-default
                show-search-result
                :address-info="route.params"
                :search-result="searchResult"
                :area-columns-placeholder="['省', '市', '区']"
                @save="onSave"
                @change-detail="onChangeDetail"
                @change-default="ChangeDefault"
            />
        </div>
    </div>
</template>

<script setup>
import {useRoute} from 'vue-router'
import {put} from '../../utils/request'
import { areaList } from '@vant/area-data';
import { NavBar } from 'vant';
import { AddressEdit } from 'vant';
import { ref } from 'vue';
const searchResult = ref([]);
//返回上一级
const route = useRoute()
console.log('addr route params:', route.params);

const onClickLeft = () => history.back()
const onChangeDetail = (val) => {
  if (val) {
    searchResult.value = [
      {
        name: '黄龙万科中心',
        address: '杭州市西湖区',
      },
    ];
  } else {
    searchResult.value = [];
  }
}

const ChangeDefault = ()=>{

} 


const onSave= async(content)=>{
    let data = {
        "name":content.name,
        "phone":content.tel,
        "area":content.areaCode,
        "area_name":`${content.province}${content.city}${content.country}`,
        "desc":content.address,
        "default_set":Number(content.isDefault)
    }
    let res = await put(`/address/` + router.params.id,data)
    console.log(res);
}

</script>

<style lang="scss" scoped>
.title{
    width: 100%;
    height: 0.5rem;
}
.address{
    margin-top: 0.1rem;
    background-color: #F7F8FA;
}
</style>